package cn.jbooter.session.autoconfigure.config.hash_map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.SessionRepository;
import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration;
import cn.jbooter.session.autoconfigure.properties.ISpringSessionProperties;

@ConditionalOnProperty(prefix = "spring.jsession", name="store-type", havingValue="hash-map")
public class SessionHashMapHttpSessionConfiguration extends SpringHttpSessionConfiguration{

	@Autowired
	private ISpringSessionProperties sessionProperties;
	
	@Bean
	public SessionRepository<ExpiringSession> sessionRepository() {
		MapSessionRepository repository = new MapSessionRepository();
		Integer timeout = sessionProperties.getTimeout();
		if (timeout != null) {
			repository.setDefaultMaxInactiveInterval(timeout);
		}
		return repository;
	}
	
}
